package com.tianji.aigc.config;

import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.tianji.aigc.memory.RedisChatMemory;
import com.tianji.aigc.tools.CourseTool;
import com.tianji.aigc.tools.OrderTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringAiConfig {


    @Autowired
    private SessionProperties sessionProperties;

    @Bean
    public ChatClient chatClient(DashScopeChatModel chatModel,
                                 MessageChatMemoryAdvisor chatMemoryAdvisor,
                                 CourseTool courseTool,
                                 OrderTool orderTool) {
        return  ChatClient.builder(chatModel)
                .defaultSystem(sessionProperties.getSystem())
                .defaultAdvisors( new SimpleLoggerAdvisor(),//日志记录器
                                    chatMemoryAdvisor//会话记忆记录器
                        )
                .defaultTools(courseTool,orderTool)
                .build();
    }


    @Bean
    public MessageChatMemoryAdvisor chatMessageAdvisor(RedisChatMemory redisChatMemory){
        return new MessageChatMemoryAdvisor(redisChatMemory);
    }


}
